home *** CD-ROM | disk | FTP | other *** search
- Path: admaix.sunydutchess.edu!ub!newserve!rebecca!rpi!not-for-mail
- From: floydb1@lib104.its.rpi.edu (Barry B Floyd)
- Newsgroups: comp.lang.c++
- Subject: Re: Leap year
- Date: 1 Apr 1996 11:11:09 -0500
- Organization: Rensselaer Polytechnic Institute, Troy, NY.
- Message-ID: <4jov6t$737@lib104.its.rpi.edu>
- References: <3135A7F2.2120@hiwaay.net> <4hbiln$899@sam.inforamp.net> <4hesba$ph@clarknet.clark.net> <3146D0D8.16BA@msn.com> <315b3f2b.912029@NEWS.CLOUD9.NET> <Dp1LD9.Mt@mv.mv.com>
- NNTP-Posting-Host: lib104.its.rpi.edu
- X-newsreader: xrn 7.04-beta-11
-
-
- I use the following to calculate 'day names', the leap year part is
- taken care of in the 'year/4...' code.
-
- One problem (of many), as mentioned by others, the change of
- calendar in various countries/empires at various times. You might
- want to test the year for inclusion in a range appropriate to
- your application.
-
- Note: this_* variables are pulic String's (a string class).
-
- // ------------------------------------------------------------
- String Dates::DayNames ( void ) // return this_day_name
- {
- int day_index ;
-
- int day = atoi ( (char *) this_day ) ;
- int month = atoi ( (char *) this_month ) ;
- int year = atoi ( (char *) this_year ) ;
-
- String days[] = { "Sun.", "Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat." } ;
-
- // ---- thanks to Tomohiko Sakamoto
-
- int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4} ;
-
- year -= month < 3 ;
-
- day_index = (year + year/4 - year/100 + year/400 + t[month-1] + day) % 7 ;
-
- // ---- end thanks
-
- this_day_name = days[day_index] ;
-
- return ( this_day_name ) ;
- }
- --
- +--------------------------------------------------------------------+
- | Barry B. Floyd \\\ floydb1@rpi.edu |
- | RPI Alum. '84 '87 '88 \\\ |
- +--------------------------------------------------------------------+
-